//
//  Session.m
//  TrainTree
//
//  Created by wanghui on 2017/8/30.
//  Copyright © 2017年 YouYeShu. All rights reserved.
//

#import "Session.h"
NSString *const SessionFilePath = @"Session";
NSString *const SessionPlist   = @"Session.plist";

@implementation Session
+ (Session *)shareSession
{
    static Session *session = nil;
    static dispatch_once_t token;
    dispatch_once(&token, ^{
        session = [[Session alloc]init];
    });
    return  session;
}

- (NSString *)userId
{
    id userId = [self attribute][@"userId"];

    return [NSString isVaildString:userId] ? userId :@"1";
}

- (NSString *)username
{
   return [self attribute][@"username"];
}
// 是否可以发布课程
- (BOOL)isPublishLesson
{
    return [self attribute][@"isPublishLesson"];
}
- (NSString *)branchId
{
    return [self attribute][@"branchId"];
}
// 部门名
- (NSString *)branchName
{
    return [self attribute][@"branchName"];
}

- (NSString *)level
{
    return [self attribute][@"level"];
}
// 等级名
- (NSString *)levelName
{
    return [self attribute][@"levelName"];
}

- (NSString *)token
{
    return [self attribute][@"token"];
}

 - (NSDictionary *)attribute
{
    return [ALCacheData objectForPlistKey:nil file:SessionFilePath plist:SessionPlist];
}

+ (void)session:(NSDictionary *)session
{
    [ALCacheData writeData:session file:SessionFilePath plist:SessionPlist];
}

+ (BOOL)isLogin
{
    return [ALCacheData isExists:SessionFilePath];
}

+ (void)exit
{
//    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
//    NSString *path = [paths objectAtIndex:0];
//    //目录下的文件夹名字'aaa'
//    NSString *pathFile = [path stringByAppendingPathComponent:@"aaa"];

    [ALCacheData removeFile:SessionFilePath];
 
}
@end
